package com.example.demo.niuke;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Author: liull
 * @Description: 获取两个字符串的最大相同字串
 * 比如：str1 = "abcwerhrlloyuiodef" str2 = "cvhellobnm"
 * 提示 ： 将短的那个串进行长度依次递减的字串与较长的比较
 * @Date: Created in 20:02 2020/3/28
 * @Modified By:
 */
public class Main42 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        //        System.out.println(Arrays.toString("127.0.0.1".split("\\.")));
        while ((line = br.readLine()) != null) {
            String r = br.readLine();
            System.out.println(getLongestSubStr(line, r));
        }

    }

    /**
     * @param m 字符串1
     * @param f 字符串2
     * @return 最长公共子串
     */
    public static String getLongestSubStr(String m, String f) {
        // m长度
        int lenM = m.length();
        // f长度
        int lenF = f.length();
        // 较长的字符串
        String longStr = lenM >= lenF ? m : f; // "abcwerhelloyuiodef"
        // 较短的字符串
        String shortStr = lenM < lenF ? m : f; //"cvhellobnm"
        // 取短的字串
        for (int i = shortStr.length(); i > 0; i--) { // 外层表示比较的长度 最长开始
            for (int j = 0; j < shortStr.length() - i + 1; j++) { //开始取字串的索引
                String substring = shortStr.substring(j, j + i);
                if (longStr.contains(substring)) {
                    return substring;
                }
            }
        }
        return "";

    }
}

